package org.huyue.huyuexia.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.huyue.huyuexia.pojo.Article;

import java.util.List;

@Mapper
public interface ArticleMapper {

    @Select("SELECT a.*, u.nickname ,u.avatar_url as avatar from users as u right join article as a on u.id = a.author_id ")
    List<Article> findAll();

    @Select("SELECT a.*, u.nickname ,u.avatar_url as avatar from users as u right join article as a on u.id = a.author_id where a.id = #{id}")
    Article findById(Integer id);

    @Insert("insert into article(title, content, url, description, author_id, create_time, update_time, status, views)" +
            "values (#{title}, #{content}, #{url}, #{description}, #{authorId}, #{createTime}, #{updateTime}, #{status}, #{views})")
    void add(Article article);

    @Update("UPDATE article SET title = #{title}, content = #{content}, url = #{url}, description = #{description}, author_id = #{authorId}, create_time = #{createTime}, update_time = #{updateTime}, status = #{status}, views = #{views} WHERE id = #{id}")
    void update(Article article);


}
